/**
 * 压缩解压缩常用方法.
 */
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const zlib = require("zlib");
/**
 * 解压工具方法.
 * @param zipContent
 */
function unzip(zipContent) {
    return new Promise((resolve, reject) => {
        var buffer = new Buffer(zipContent, 'base64');
        zlib.unzip(buffer, function (err, _buffer) {
            if (!err) {
                resolve(_buffer.toString());
            }
            else {
                console.error(err.stack);
                reject(err);
            }
        });
    });
}
exports.unzip = unzip;
function zip(contentStr) {
    return new Promise((resolve, reject) => {
        zlib.deflate(contentStr, function (err, buffer) {
            let content = buffer.toString('base64');
            err ? reject(err) : resolve(content);
        });
    });
}
exports.zip = zip;
function gzip(contentStr) {
    return new Promise((resolve, reject) => {
        zlib.gzip(contentStr, (err, buffer) => {
            let content = buffer.toString('base64');
            err ? reject(err) : resolve(content);
        });
    });
}
exports.gzip = gzip;
/**
 * 解压
 * @param data
 * @returns {Promise}
 */
function unGzip(data) {
    return new Promise((resolve, reject) => {
        //console.info('开始解压数据:' + data.toString());
        let buf = new Buffer(data, 'base64');
        zlib.gunzip(buf, (error, result) => {
            if (error) {
                console.error('解压数据出错,error=' + error);
                reject('解压数据出错,error=' + error);
            }
            resolve(result.toString());
        });
    });
}
exports.unGzip = unGzip;
